//
//  FJLoadingView.swift
//  FruitJuice
//
//  Created by Rae on 2023/12/20.
//

import UIKit
import SwiftEntryKit

class FJLoadingView: UIView, FJLottieAnimationProtocol, SAAnimationDelegate {
    
    func animationContainerViewStyle() -> SAAnimationViewStyle {
        .center
    }
    
    func animation(customAttributes attributes: EKAttributes) -> EKAttributes {
        var attribute = attributes
        attribute.displayDuration = .infinity
        attribute.screenBackground = .color(color: .black.with(alpha: 0))
        attribute.entryInteraction = .absorbTouches
        attribute.scroll = .disabled
        attribute.entranceAnimation = .init(fade: .init(from: 0, to: 1, duration: 0.3))
        attribute.exitAnimation = .init(fade: .init(from: 1, to: 0, duration: 0.3))
        attribute.popBehavior = .animated(animation: .init(fade: .init(from: 1, to: 0, duration: 0.3)))
        attribute.positionConstraints.size = .screen
        return attribute
    }
    
    private lazy var animateView: FJLottieAnimationView = {
        animation.make(.loading, contentMode: UIView.ContentMode.scaleAspectFit)
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .black.alpha(0.2)
        subviews {
            animateView
        }
//        animateView.fillContainer()
        animateView.size(150)
        animateView.alpha = 1
        animateView.centerInContainer()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
